<?php


namespace Leave\Controller;

use Think\Controller;


class IndexController extends Controller
{
    /**
     * 业务逻辑都放在 WeiboApi 中
     * @var
     */
    // const MODEL_NAME = 'Leave@:';
    public function index()
    {
        $leave = M('core_leave');
        $map['status']=array('neq',-1);
        $count      = $leave->where($map)->count();// 查询满足要求的总记录数
        $Page       = new \Think\Page($count,5);// 实例化分页类 传入总记录数和每页显示的记录数(25)
        $show       = $Page->show();// 分页显示输出
        $list       = $leave->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();
        foreach ($list as $key => $value) {
            $leave = M('core_leave_type')->where('id = '.$value['type'])->getField('title');
            $list[$key]['lname'] = $leave;
        }
        $this->assign('page',$show);// 赋值分页输出

        $this->assign('_list',$list);
        $this->display();
    }

    public function pass()
    {

        $ids   = I('request.id');
        $model = I('request.model');
        if (!$ids) {
            $this->error('无可操作数据!');
        }

        $map['id']    = array('in', $ids);
        $method       = I('request.method');
        $model_object = D($model);
        switch ($method) {
            case 'pass':
               $dd['status']=1;
               $dd['check_time']=time();
               $d=M('core_leave')->where('id='.I('id'))->save($dd);
               $this->success('通过成功',U('index'));
                break;
            case 'nopass':
               $dd['status']=2;
               $dd['check_time']=0;
               $d=M('core_leave')->where('id='.I('id'))->save($dd);
               $this->success('取消通过',U('index'));
                break;
        }
    }
    public function collect()
    {
        $map['status']=array('neq',-1);
        $list=M('core_leave')->where($map)->select();
        $total=count($list);
        $succ=0;
        $erro=0;
        foreach ($list as $key => $value) {
            if($value['status']==1){
                $succ++;
            }
            if($value['status']==2){
                $erro++;
            }
        }
        $this->assign('total',$total);
        $this->assign('succ',$succ);
        $this->assign('erro',$erro);
        $this->display();
    }
}
            
